package com.dmall.algorithm.chapter03;

/**
 * 盛最多水的容器
 * 采用双指针解法
 */
public class Leetcode11V2 {

    public int maxArea(int[] height) {
        int left = 0;
        int right = height.length - 1;
        int maxArea = 0;
        while (left < right) {
            int area = (right - left) * (height[left] > height[right] ? height[right--] : height[left++]);
            maxArea = Math.max(maxArea, area);
        }
        return maxArea;
    }

    public static void main(String[] args) {
        Leetcode11V2 leetcode11 = new Leetcode11V2();
        int[] height = {1,8,6,2,5,4,8,3,7};
        int maxArea = leetcode11.maxArea(height);
        System.out.println(maxArea);
    }
}
